
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>多线程 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="ntlm-pian/README.md" />
    
    
    <link rel="prev" href="5. 端口扫描与服务爆破.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="./">
            
                <a href="./">
            
                    
                    前言
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="kerberos/README.md">
            
                <span>
            
                    
                    基础篇
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="2. 基础.html">
            
                <a href="2. 基础.html">
            
                    
                    基础知识
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="3. 脚本编写与执行.html">
            
                <a href="3. 脚本编写与执行.html">
            
                    
                    脚本编写与执行
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="4. Scoket网络编程.html">
            
                <a href="4. Scoket网络编程.html">
            
                    
                    Scoket网络编程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="5. 端口扫描与服务爆破.html">
            
                <a href="5. 端口扫描与服务爆破.html">
            
                    
                    端口扫描与服务爆破
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.2.5" data-path="6. 多线程.html">
            
                <a href="6. 多线程.html">
            
                    
                    多线程
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="ntlm-pian/README.md">
            
                <span>
            
                    
                    进阶篇
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="7. WMI对象操作.html">
            
                <a href="7. WMI对象操作.html">
            
                    
                    WMI&dot-net对象操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="8. Win32API.html">
            
                <a href="8. Win32API.html">
            
                    
                    Win32API
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="9. Dll注入&shellcode注入&exe注入.html">
            
                <a href="9. Dll注入&shellcode注入&exe注入.html">
            
                    
                    注入操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="10. 混淆.html">
            
                <a href="10. 混淆.html">
            
                    
                    混淆
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="11. 日志操作.html">
            
                <a href="11. 日志操作.html">
            
                    
                    日志操作
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="ldap-pian/README.md">
            
                <span>
            
                    
                    应用篇
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="12. 实例使用场景.html">
            
                <a href="12. 实例使用场景.html">
            
                    
                    实例使用场景
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="13. Framework.html">
            
                <a href="13. Framework.html">
            
                    
                    Framework
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="." >多线程</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h2 id="powershell6-multithreading">powershell(6)-Multithreading</h2>
<p>powershell&#x7684;&#x591A;&#x7EBF;&#x7A0B;&#x662F;&#x6211;&#x4EEC;&#x5728;&#x4F7F;&#x7528;powershell&#x8FDB;&#x884C;&#x6E17;&#x900F;&#x8FC7;&#x7A0B;&#x4E2D;&#x5FC5;&#x987B;&#x4F7F;&#x7528;&#x5230;&#x7684;&#x529F;&#x80FD;&#xFF01;&#x4E3A;&#x4EC0;&#x4E48;&#x5462;&#xFF1F;&#x8BD5;&#x60F3;&#xFF0C;&#x5F53;&#x4F60;&#x5230;&#x8FBE;&#x5BF9;&#x65B9;&#x5185;&#x7F51;&#xFF0C;&#x4F60;&#x9700;&#x8981;&#x5217;&#x51FA;&#x7528;&#x6237;&#xFF0C;&#x6216;&#x8005;&#x4E0B;&#x8F7D;&#x6587;&#x4EF6;&#x7B49;&#x7B49;&#x64CD;&#x4F5C;&#x7684;&#x65F6;&#x5019;&#x4F60;&#x662F;&#x9009;&#x62E9;&#x7B49;&#x5F85;&#x51E0;&#x5929;&#x8FD8;&#x662F;&#x51E0;&#x5206;&#x949F;&#x641E;&#x5B9A;&#x5462;&#xFF1F;&#x6211;&#x4EEC;&#x901A;&#x8FC7;&#x5185;&#x5B58;&#x548C;CPU&#x7684;&#x5360;&#x7528;&#x6765;&#x63D0;&#x9AD8;&#x6548;&#x7387;&#xFF0C;&#x4E5F;&#x5C31;&#x662F;&#x6211;&#x4EEC;&#x901A;&#x5E38;&#x7B97;&#x6CD5;&#x4E0A;&#x8BF4;&#x7684;&#x7528;&#x7A7A;&#x95F4;&#x6765;&#x6362;&#x53D6;&#x65F6;&#x95F4;&#x3002;&#x673A;&#x5668;&#x914D;&#x7F6E;&#x9AD8;&#xFF0C;&#x6709;&#x7684;&#x7528;&#xFF0C;&#x800C;&#x4E0D;&#x7528;&#x5C31;&#x662F;&#x6D6A;&#x8D39;&#x3002;</p>
<h3 id="powershell&#x81EA;&#x5E26;&#x7684;job">powershell&#x81EA;&#x5E26;&#x7684;Job</h3>
<p>&#x8FD9;&#x91CC;&#x4F7F;&#x7528;&#x7F51;&#x4E0A;&#x4E00;&#x4E2A;&#x4F8B;&#x5B50;</p>
<pre><code class="lang-powershell"><span class="hljs-comment"># &#x4E0D;&#x4F7F;&#x7528;&#x591A;&#x7EBF;&#x7A0B;</span>
<span class="hljs-variable">$start</span> = <span class="hljs-built_in">Get-Date</span>
<span class="hljs-variable">$code1</span> = { <span class="hljs-built_in">Start-Sleep</span> -Seconds <span class="hljs-number">5</span>; <span class="hljs-string">&apos;A&apos;</span> }
<span class="hljs-variable">$code2</span> = { <span class="hljs-built_in">Start-Sleep</span> -Seconds <span class="hljs-number">5</span>; <span class="hljs-string">&apos;B&apos;</span>}
<span class="hljs-variable">$code3</span> = { <span class="hljs-built_in">Start-Sleep</span> -Seconds <span class="hljs-number">5</span>; <span class="hljs-string">&apos;C&apos;</span>}

<span class="hljs-variable">$result1</span>,<span class="hljs-variable">$result2</span>,<span class="hljs-variable">$result3</span>= (&amp; <span class="hljs-variable">$code1</span>),(&amp; <span class="hljs-variable">$code2</span>),(&amp; <span class="hljs-variable">$code3</span>)

<span class="hljs-variable">$end</span> =<span class="hljs-built_in">Get-Date</span>
<span class="hljs-variable">$timespan</span>= <span class="hljs-variable">$end</span> - <span class="hljs-variable">$start</span>
<span class="hljs-variable">$seconds</span> = <span class="hljs-variable">$timespan</span>.TotalSeconds

<span class="hljs-built_in">Write-Host</span> <span class="hljs-string">&quot;&#x603B;&#x8017;&#x65F6; <span class="hljs-variable">$seconds</span> &#x79D2;.&quot;</span>
</code></pre>
<pre><code class="lang-powershell"><span class="hljs-comment"># &#x4F7F;&#x7528;&#x591A;&#x7EBF;&#x7A0B;</span>
<span class="hljs-variable">$start</span> = <span class="hljs-built_in">Get-Date</span>
<span class="hljs-variable">$code1</span> = { <span class="hljs-built_in">Start-Sleep</span> -Seconds <span class="hljs-number">5</span>; <span class="hljs-string">&apos;A&apos;</span> }
<span class="hljs-variable">$code2</span> = { <span class="hljs-built_in">Start-Sleep</span> -Seconds <span class="hljs-number">5</span>; <span class="hljs-string">&apos;B&apos;</span>}
<span class="hljs-variable">$code3</span> = { <span class="hljs-built_in">Start-Sleep</span> -Seconds <span class="hljs-number">5</span>; <span class="hljs-string">&apos;C&apos;</span>}

<span class="hljs-variable">$job1</span> = Start-Job -ScriptBlock <span class="hljs-variable">$code1</span>
<span class="hljs-variable">$job2</span> = Start-Job -ScriptBlock <span class="hljs-variable">$code2</span>
<span class="hljs-variable">$job3</span> = Start-Job -ScriptBlock <span class="hljs-variable">$code3</span>

<span class="hljs-variable">$alljobs</span> =  Wait-Job <span class="hljs-variable">$job1</span>,<span class="hljs-variable">$job2</span>,<span class="hljs-variable">$job3</span>
<span class="hljs-variable">$result1</span>,<span class="hljs-variable">$result2</span>,<span class="hljs-variable">$result3</span> = Receive-Job <span class="hljs-variable">$alljobs</span>

<span class="hljs-variable">$end</span> =<span class="hljs-built_in">Get-Date</span>

<span class="hljs-variable">$timespan</span>= <span class="hljs-variable">$end</span> - <span class="hljs-variable">$start</span>
<span class="hljs-variable">$seconds</span> = <span class="hljs-variable">$timespan</span>.TotalSeconds
<span class="hljs-built_in">Write-Host</span> <span class="hljs-string">&quot;&#x603B;&#x8017;&#x65F6; <span class="hljs-variable">$seconds</span> &#x79D2;.&quot;</span>
</code></pre>
<p>&#x90A3;&#x4E48;&#x53EF;&#x4EE5;&#x6D4B;&#x8BD5;&#x5230;&#x8FD9;&#x4E24;&#x4E2A;&#x811A;&#x672C;&#x786E;&#x5B9E;&#x611F;&#x89C9;&#x4E0A;&#x662F;&#x4F7F;&#x7528;&#x4E86;&#x591A;&#x7EBF;&#x7A0B;&#xFF0C;&#x56E0;&#x4E3A;&#x7B2C;&#x4E8C;&#x4E2A;&#x7248;&#x672C;&#x4F7F;&#x7528;&#x65F6;&#x95F4;&#x53EA;&#x6709;9s&#x5DE6;&#x53F3;&#x7684;&#x65F6;&#x95F4;&#xFF0C;&#x4F46;&#x5982;&#x679C;&#x5206;&#x6765;&#x6267;&#x884C;&#x662F;&#x9700;&#x8981;15s&#x7684;&#xFF0C;&#x5C31;&#x5982;&#x7B2C;&#x4E00;&#x4E2A;&#x7248;&#x672C;&#x3002;&#x90A3;&#x4E48;&#x8FD9;&#x91CC;&#x662F;&#x771F;&#x7684;&#x4F7F;&#x7528;&#x4E86;&#x591A;&#x7EBF;&#x7A0B;&#x4E48;&#xFF1F;&#x5176;&#x5B9E;&#x771F;&#x5B9E;&#x60C5;&#x51B5;&#x662F;&#x591A;&#x8FDB;&#x7A0B;&#xFF0C;&#x6700;&#x7B80;&#x5355;&#x7684;&#x67E5;&#x770B;&#x65B9;&#x5F0F;&#xFF0C;&#x6253;&#x5F00;&#x4EFB;&#x52A1;&#x7BA1;&#x7406;&#x5668;&#xFF0C;&#x518D;&#x6267;&#x884C;&#x811A;&#x672C;&#x4F60;&#x53EF;&#x4EE5;&#x770B;&#x5230;&#x591A;&#x51FA;3&#x4E2A;powershell.exe&#x7684;&#x8FDB;&#x7A0B;&#x3002;</p>
<p>&#x90A3;&#x4E48;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x7528;&#x8FD9;&#x4E2A;&#x591A;&#x8FDB;&#x7A0B;&#x4E48;&#xFF1F;&#x662F;&#x53EF;&#x4EE5;&#x7528;&#xFF0C;&#x4F46;&#x662F;&#x9700;&#x8981;&#x6CE8;&#x610F;&#x6BCF;&#x4E2A;&#x8FDB;&#x7A0B;&#x90FD;&#x9700;&#x8981;&#x8DE8;&#x8FDB;&#x7A0B;&#x4EA4;&#x6362;&#x6570;&#x636E;&#xFF0C;&#x800C;&#x4E14;&#x6CA1;&#x6709;&#x8282;&#x6D41;&#x7684;&#x673A;&#x5236;&#xFF0C;&#x6240;&#x4EE5;&#x6211;&#x4EEC;&#x8FD8;&#x662F;&#x6765;&#x770B;&#x770B;&#x771F;&#x6B63;&#x7684;&#x591A;&#x7EBF;&#x7A0B;&#x5427;&#x3002;</p>
<h3 id="&#x591A;&#x7EBF;&#x7A0B;">&#x591A;&#x7EBF;&#x7A0B;</h3>
<p>&#x76F4;&#x63A5;&#x6765;&#x770B;&#x4E00;&#x6BB5;&#x4EE3;&#x7801;</p>
<pre><code class="lang-powershell"><span class="hljs-variable">$code</span> = { <span class="hljs-built_in">Start-Sleep</span> -Seconds <span class="hljs-number">2</span>; <span class="hljs-string">&quot;Hello&quot;</span> }
<span class="hljs-variable">$newPowerShell</span> = [PowerShell]::Create().AddScript(<span class="hljs-variable">$code</span>)
<span class="hljs-variable">$newPowerShell</span>.Invoke()
</code></pre>
<p>&#x8FD9;&#x6837;&#x6211;&#x4EEC;&#x901A;&#x8FC7;powershell&#x7684;API&#x8FD0;&#x884C;&#x4E00;&#x4E2A;&#x4EE3;&#x7801;&#x5757;&#xFF0C;&#x5C31;&#x7B97;&#x662F;&#x5728;&#x4E00;&#x4E2A;&#x8FDB;&#x7A0B;&#x5185;&#x6267;&#x884C;&#x4E86;&#x4EE3;&#x7801;&#xFF0C;&#x4E0D;&#x4F1A;&#x521B;&#x5EFA;&#x65B0;&#x7684;&#x8FDB;&#x7A0B;&#x3002;&#x8FD9;&#x662F;&#x5355;&#x7EBF;&#x7A0B;&#xFF0C;&#x90A3;&#x4E48;&#x5982;&#x4F55;&#x591A;&#x7EBF;&#x7A0B;&#x5462;&#xFF1F;&#x4E0B;&#x9762;&#x7684;&#x4EE3;&#x7801;&#x5C31;&#x53EF;&#x4EE5;&#x5B9E;&#x73B0;&#x5566;&#xFF0C;&#x90A3;&#x4E48;&#x6D4B;&#x8BD5;&#x8FC7;&#x7A0B;&#x4E2D;&#x63A8;&#x8350;windows&#x7684;<code>process explorer</code>&#x6765;&#x67E5;&#x770B;&#x8FDB;&#x7A0B;&#x5BF9;&#x5E94;&#x7684;&#x7EBF;&#x7A0B;&#xFF0C;&#x53EF;&#x4EE5;&#x6E05;&#x6670;&#x7684;&#x770B;&#x5230;&#x521B;&#x5EFA;&#x7684;&#x7EBF;&#x7A0B;&#x3002;</p>
<pre><code class="lang-powershell">
<span class="hljs-comment"># &#x8BBE;&#x7F6E;&#x7EBF;&#x7A0B;&#x9650;&#x5236;&#x4E3A;4&#xFF0C;&#x90A3;&#x4E48;&#x5982;&#x679C;&#x4E00;&#x8D77;&#x542F;&#x52A8;&#x8D85;&#x8FC7;4&#x7EBF;&#x7A0B;&#x5C31;&#x9700;&#x8981;&#x6392;&#x961F;&#x7B49;&#x5F85;</span>
<span class="hljs-variable">$throttleLimit</span> = <span class="hljs-number">4</span>
<span class="hljs-comment"># &#x521B;&#x5EFA;&#x7EBF;&#x7A0B;&#x6C60;</span>
<span class="hljs-variable">$SessionState</span> = [system.management.automation.runspaces.initialsessionstate]::CreateDefault()
<span class="hljs-variable">$Pool</span> = [runspacefactory]::CreateRunspacePool(<span class="hljs-number">1</span>, <span class="hljs-variable">$throttleLimit</span>, <span class="hljs-variable">$SessionState</span>, <span class="hljs-variable">$Host</span>)
<span class="hljs-variable">$Pool</span>.Open()

<span class="hljs-comment"># &#x4EE3;&#x7801;&#x5757;</span>
<span class="hljs-variable">$ScriptBlock</span> = {
    <span class="hljs-keyword">param</span>(<span class="hljs-variable">$id</span>)

    <span class="hljs-built_in">Start-Sleep</span> -Seconds <span class="hljs-number">2</span>
    <span class="hljs-string">&quot;Done processing ID <span class="hljs-variable">$id</span>&quot;</span>
}

<span class="hljs-variable">$threads</span> = @()

<span class="hljs-comment"># &#x521B;&#x5EFA;40&#x4E2A;&#x7EBF;&#x7A0B;</span>
<span class="hljs-variable">$handles</span> = <span class="hljs-keyword">for</span> (<span class="hljs-variable">$x</span> = <span class="hljs-number">1</span>; <span class="hljs-variable">$x</span> <span class="hljs-nomarkup">-le</span> <span class="hljs-number">40</span>; <span class="hljs-variable">$x</span>++) {
    <span class="hljs-variable">$powershell</span> = [powershell]::Create().AddScript(<span class="hljs-variable">$ScriptBlock</span>).AddArgument(<span class="hljs-variable">$x</span>)
    <span class="hljs-variable">$powershell</span>.RunspacePool = <span class="hljs-variable">$Pool</span>
    <span class="hljs-variable">$powershell</span>.BeginInvoke()
    <span class="hljs-variable">$threads</span> += <span class="hljs-variable">$powershell</span>
}

<span class="hljs-comment"># &#x83B7;&#x53D6;&#x6570;&#x636E;</span>
<span class="hljs-keyword">do</span> {
  <span class="hljs-variable">$i</span> = <span class="hljs-number">0</span>
  <span class="hljs-variable">$done</span> = <span class="hljs-literal">$true</span>
  <span class="hljs-keyword">foreach</span> (<span class="hljs-variable">$handle</span> <span class="hljs-keyword">in</span> <span class="hljs-variable">$handles</span>) {
    <span class="hljs-keyword">if</span> (<span class="hljs-variable">$handle</span> <span class="hljs-nomarkup">-ne</span> <span class="hljs-literal">$null</span>) {
      <span class="hljs-keyword">if</span> (<span class="hljs-variable">$handle</span>.IsCompleted) {
        <span class="hljs-variable">$threads</span>[<span class="hljs-variable">$i</span>].EndInvoke(<span class="hljs-variable">$handle</span>)
        <span class="hljs-variable">$threads</span>[<span class="hljs-variable">$i</span>].Dispose()
        <span class="hljs-variable">$handles</span>[<span class="hljs-variable">$i</span>] = <span class="hljs-literal">$null</span>
      } <span class="hljs-keyword">else</span> {
        <span class="hljs-variable">$done</span> = <span class="hljs-literal">$false</span>
      }
    }
    <span class="hljs-variable">$i</span>++
  }
  <span class="hljs-keyword">if</span> (<span class="hljs-nomarkup">-not</span> <span class="hljs-variable">$done</span>) { <span class="hljs-built_in">Start-Sleep</span> -Milliseconds <span class="hljs-number">500</span> }
} <span class="hljs-keyword">until</span> (<span class="hljs-variable">$done</span>)
</code></pre>
<p>&#x5927;&#x5BB6;&#x53EF;&#x4EE5;&#x8BD5;&#x4E00;&#x8BD5;&#x4E0B;&#x9762;&#x7684;&#x4EE3;&#x7801;&#x548C;&#x5355;&#x72EC;&#x6267;&#x884C;<code>get-hotfix</code>&#x7684;&#x901F;&#x5EA6;&#x5DEE;&#x522B;&#xFF1A;</p>
<pre><code class="lang-powershell"><span class="hljs-variable">$throttleLimit</span> = <span class="hljs-number">40</span>
<span class="hljs-variable">$SessionState</span> = [system.management.automation.runspaces.initialsessionstate]::CreateDefault()
<span class="hljs-variable">$Pool</span> = [runspacefactory]::CreateRunspacePool(<span class="hljs-number">1</span>, <span class="hljs-variable">$throttleLimit</span>, <span class="hljs-variable">$SessionState</span>, <span class="hljs-variable">$Host</span>)
<span class="hljs-variable">$Pool</span>.Open()

<span class="hljs-variable">$ScriptBlock</span> = {
    get-HotFix
}
<span class="hljs-variable">$threads</span> = @()
<span class="hljs-variable">$handles</span> = <span class="hljs-keyword">for</span> (<span class="hljs-variable">$x</span> = <span class="hljs-number">1</span>; <span class="hljs-variable">$x</span> <span class="hljs-nomarkup">-le</span> <span class="hljs-number">40</span>; <span class="hljs-variable">$x</span>++) {
    <span class="hljs-variable">$powershell</span> = [powershell]::Create().AddScript(<span class="hljs-variable">$ScriptBlock</span>)
    <span class="hljs-variable">$powershell</span>.RunspacePool = <span class="hljs-variable">$Pool</span>
    <span class="hljs-variable">$powershell</span>.BeginInvoke()
    <span class="hljs-variable">$threads</span> += <span class="hljs-variable">$powershell</span>
}

<span class="hljs-keyword">do</span> {
  <span class="hljs-variable">$i</span> = <span class="hljs-number">0</span>
  <span class="hljs-variable">$done</span> = <span class="hljs-literal">$true</span>
  <span class="hljs-keyword">foreach</span> (<span class="hljs-variable">$handle</span> <span class="hljs-keyword">in</span> <span class="hljs-variable">$handles</span>) {
    <span class="hljs-keyword">if</span> (<span class="hljs-variable">$handle</span> <span class="hljs-nomarkup">-ne</span> <span class="hljs-literal">$null</span>) {
      <span class="hljs-keyword">if</span> (<span class="hljs-variable">$handle</span>.IsCompleted) {
        <span class="hljs-variable">$threads</span>[<span class="hljs-variable">$i</span>].EndInvoke(<span class="hljs-variable">$handle</span>)
        <span class="hljs-variable">$threads</span>[<span class="hljs-variable">$i</span>].Dispose()
        <span class="hljs-variable">$handles</span>[<span class="hljs-variable">$i</span>] = <span class="hljs-literal">$null</span>
      } <span class="hljs-keyword">else</span> {
        <span class="hljs-variable">$done</span> = <span class="hljs-literal">$false</span>
      }
    }
    <span class="hljs-variable">$i</span>++
  }
  <span class="hljs-keyword">if</span> (<span class="hljs-nomarkup">-not</span> <span class="hljs-variable">$done</span>) { <span class="hljs-built_in">Start-Sleep</span> -Milliseconds <span class="hljs-number">500</span> }
} <span class="hljs-keyword">until</span> (<span class="hljs-variable">$done</span>)
</code></pre>
<p>&#x90A3;&#x4E48;&#x4EE5;&#x540E;&#x5927;&#x5BB6;&#x9700;&#x8981;&#x6267;&#x884C;&#x7684;&#x4EE3;&#x7801;&#x5C31;&#x5199;&#x5728;&#x811A;&#x672C;&#x5757;&#x533A;&#x57DF;&#x5373;&#x53EF;&#x3002;&#x8FD9;&#x91CC;&#x548C;&#x524D;&#x9762;&#x7684;&#x7206;&#x7834;&#x811A;&#x672C;&#x7ED3;&#x5408;&#x8D77;&#x6765;&#x5C31;&#x662F;&#x4E00;&#x4E2A;&#x5B8C;&#x7F8E;&#x7684;&#x7206;&#x7834;&#x811A;&#x672C;&#x548C;&#x4FE1;&#x606F;&#x6536;&#x96C6;&#x811A;&#x672C;&#x3002;</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="5. 端口扫描与服务爆破.html" class="navigation navigation-prev " aria-label="Previous page: 端口扫描与服务爆破">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="ntlm-pian/README.md" class="navigation navigation-next " aria-label="Next page: 进阶篇">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"多线程","level":"1.2.5","depth":2,"next":{"title":"进阶篇","level":"1.3","depth":1,"path":"ntlm-pian/README.md","ref":"ntlm-pian/README.md","articles":[{"title":"WMI&dot-net对象操作","level":"1.3.1","depth":2,"path":"7. WMI对象操作.md","ref":"7. WMI对象操作.md","articles":[]},{"title":"Win32API","level":"1.3.2","depth":2,"path":"8. Win32API.md","ref":"8. Win32API.md","articles":[]},{"title":"注入操作","level":"1.3.3","depth":2,"path":"9. Dll注入&shellcode注入&exe注入.md","ref":"9. Dll注入&shellcode注入&exe注入.md","articles":[]},{"title":"混淆","level":"1.3.4","depth":2,"path":"10. 混淆.md","ref":"10. 混淆.md","articles":[]},{"title":"日志操作","level":"1.3.5","depth":2,"path":"11. 日志操作.md","ref":"11. 日志操作.md","articles":[]}]},"previous":{"title":"端口扫描与服务爆破","level":"1.2.4","depth":2,"path":"5. 端口扫描与服务爆破.md","ref":"5. 端口扫描与服务爆破.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":["livereload"],"pluginsConfig":{"livereload":{},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"6. 多线程.md","mtime":"2020-04-13T05:44:39.166Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-04-13T09:56:21.455Z"},"basePath":".","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="gitbook/gitbook.js"></script>
    <script src="gitbook/theme.js"></script>
    
        
        <script src="gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

